// pages/store/orderList/index.js
import {
  getStoreOrderListApi
} from '../../../https/store'
import {
  BASE_URL
} from '../../../constant/index'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    BASE_URL,
    orderList: [],
    page: 1,
    limit: 20,
    total: 100,
    status: -2 // 状态
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.getOrderList()
  },
  async getOrderList() {
    const {
      page,
      limit,
      status
    } = this.data
    const getRes = await getStoreOrderListApi({
      page,
      limit,
      status
    })
    console.log(getRes)
    if (getRes.code == 200) {
      this.setData({
        orderList: getRes.data.list
      })
    }
  },
  // 状态切换
  onChange(e) {
    console.log(e)
    let status
    switch (e.detail.title) {
      case '全部':
        status = -2
        break;
      case '已取消':
        status = -1
        break;
      case '待付款':
        status = 0
        break;
      case '待发货':
        status = 1
        break;
      case '待收货':
        status = 2
        break;
      case '已完成':
        status = 3
        break;
      case '已退款':
        status = 4
        break;
      default:
        break;
    }
    this.setData({
      status
    })
    this.getOrderList()
  },
  // 跳转订单详情页面
  gotoDetail(e) {
    const docid = e.currentTarget.dataset.docid
    wx.navigateTo({
      url: '../order/index?docid=' + docid,
    })
  }
})